$().ready(function() {
	validateRule();
});

if($("#mineLevel").val()==0){
	$("#maxLevel").attr("checked","checked");
	$("#small").hide();
} else if($("#mineLevel").val()==1){
	$("#smalLevel").attr("checked","checked");
	$("#max").hide();
}


$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});
function save() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "/wx/goodsClass/save",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			name : {
				required : true
			}
		},
		messages : {
			name : {
				required : icon + "请输入分类名称"
			}
		}
	})
}



layui.use('upload', function () {
    var upload = layui.upload;
    //执行实例
    var uploadInst_a = upload.render({
        elem: '#file_upload_a', //绑定元素
        url: '/common/sysFile/upload', //上传接口
        size: 20480,
        accept: 'file',
        done: function (r) {
            layer.msg(r.msg);
            // app.getData();
            console.log(r);
            console.log(r.fileName);
            $("#imgurl_a").html("<img src='" + r.fileName + "' style='width:80px;height:80px;'>");
            $("#imgA").val(r.fileName);
        },
        error: function (r) {
            layer.msg(r.msg);
        }
    });
	var uploadInst_b = upload.render({
		elem: '#file_upload_b', //绑定元素
		url: '/common/sysFile/upload', //上传接口
		size: 1000,
		accept: 'file',
		done: function (r) {
			layer.msg(r.msg);
			// app.getData();
			console.log(r);
			console.log(r.fileName);
			$("#imgurl_b").html("<img src='" + r.fileName + "' style='width:80px;height:80px;'>");
			$("#imgB").val(r.fileName);
		},
		error: function (r) {
			layer.msg(r.msg);
		}
	});
	var uploadInst_c = upload.render({
		elem: '#file_upload_c', //绑定元素
		url: '/common/sysFile/upload', //上传接口
		size: 1000,
		accept: 'file',
		done: function (r) {
			layer.msg(r.msg);
			// app.getData();
			console.log(r);
			console.log(r.fileName);
			$("#imgurl_c").html("<img src='" + r.fileName + "' style='width:80px;height:80px;'>");
			$("#imgC").val(r.fileName);
		},
		error: function (r) {
			layer.msg(r.msg);
		}
	});
});
